<?
	
	//require_once('../fun/accounts.php');
	$results = array();
	require_once('../fun/theories.php');
	if(isset($_POST['id']))
	{
		$row = $_POST;
		$results = ValidateTheory($row);
		if($results === true)
		$results = SaveTheory($row);
		if($results === TRUE)
		{
			redirect_to("index.php");
		}
	}else{
		$row = GetTheory($_REQUEST['id']);
	}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>&psi; db: Edit Information on <?=$row['Name']?></title>
<? include ("../inc/required-links.php") ?>
</head>

<body>
<div id="wrapper">
	<div id="l_l"></div> 
    <div id="left">
		<?php include ('../nav/theories.php') ?>
    </div>
    <div id="main">
		<?php include ('../inc/header.php') ?>
        <div id="t_bg"></div>
        <div id="content">
			<div class="otstup">
            	<div id="main_left">
            		<h1 style="text-align:center;">Edit: </h1>
					<div class="corners">
                    	<div class="text">
                    		            	
            	<dl class="error">
            		<? foreach ($results as $key => $value): ?>
						<dt><?=$key?></dt>
						<dd><?=$value?></dd>
					<? endforeach; ?>
            	</dl>
            	
                <form class="editForm formPost" method="post" action="edit.php" style="width:420px;">
                    <div class="modal-header" style="text-align:center;"><h1><?=$row['Name']?></h1></div>
                    <div>
                        <label for="Name">Name:</label>
                        <div>
                            <input type="text" name="Name" id="Name" value="<?=$row['Name']?>"
                            class="required <?=isset($results['Name']) ? 'error' : '' ?>" style="width:400px;" />
                            <span class="error"><?=isset($results['Name']) ? $results['Name'] : '' ?></span>
                        </div>
                    </div>
                    <div>
                        <label for="Year">Year:</label>
                        <div>
                            <input type="text" name="Year" id="Year" value="<?=$row['Year']?>"
                            class="required <?=isset($results['Year']) ? 'error' : '' ?>" style="width:400px;" />
                            <span class="error"><?=isset($results['Year']) ? $results['Year'] : '' ?></span>
                        </div>
                    </div>
                    <div>
                        <label for="Description">Description:</label>
                        <div>
                            <input type="text" name="Description" id="Description" value="<?=$row['Description']?>"
                            class="required <?=isset($results['Description']) ? 'error' : '' ?>" style="width:400px;" />
                            <span class="error"><?=isset($results['Description']) ? $results['Description'] : '' ?></span>
                        </div>
                    </div>
                    <div class="control-group modal-footer">
                       <input type="hidden" name="id" id="id" value="<?=$row['id']?>" />
                       <input class="btn btn-mini" style="margin-top:10px;" type="submit" value="Update" />
                    </div>
                </form>
                <br /><a href="http://cs.newpaltz.edu<?=$_GET['returnUrl']?>">Cancel</a>

                        </div>
                    </div>
                </div>
                <div id="right">
					<?php include ('../inc/cat_box1.php') ?>
					<?php include ('../inc/cat_box3.php') ?>
					<?php include ('../inc/cat_box4.php') ?>
					<?php include ('../inc/sn_links.php') ?>
                </div>
        		<div class="clear"></div>
        	</div>
        </div>
        <div class="clear"></div>  
        <div id="foot">
        	<?php include ('../inc/footer.php') ?>
		</div>
		<?php include ('../inc/copywright.php') ?>
        </div>
<div class="clear"></div> 
</div>
</body>
</html>
<? include ("../inc/required-js.php") ?>
